package com.cetccloud.ap.config.handler;

import cn.hutool.core.util.ReflectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.handler.AbstractHandlerMapping;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import javax.annotation.PostConstruct;

/**
 * @ClassName TestHandlerMapping
 * @Description TODO
 * @Author superz
 * @Date 2021/4/9 21:33
 * @Version 1.0
 **/
@Slf4j
//@Component
public class TestHandlerMapping extends AbstractHandlerMapping {

    @Autowired
    private TestHandlerController testHandlerController;

    @Override
    public int getOrder() {
        return Ordered.HIGHEST_PRECEDENCE + 1;
    }

    @PostConstruct
    private void init() {
        log.info("init TestHandlerMapping");
    }

    @Override
    protected Mono<?> getHandlerInternal(ServerWebExchange exchange) {
        HandlerMethod handlerMethod = new HandlerMethod(testHandlerController, ReflectUtil.getMethodByName(testHandlerController.getClass(), "rest1"));
        return Mono.justOrEmpty(handlerMethod);
    }
}
